import axios from "axios";
const api = axios.create({
    baseURL: import.meta.env.VITE_BASE_URL,
    timeout: 1000 * 20,
    headers: { 'X-Custom-Header': 'foobar' }
});
// Add a request interceptor
api.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
});

// Add a response interceptor
api.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    // if (response.res.data != 1000) {
    //     if (response.res.data == 403) {
    //         return Promise.reject(没有权限);
    //     }
    //     else if (response.res.data == 404) {
    //         return Promise.reject(未找到资源);
    //     }
    //     else if (response.res.data == 500) {
    //         return Promise.reject(服务器出错);
    //     }
    // }
    return response;
}, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
});
export default api